from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-20 14:13:01.223340
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 20, Sep, 2021
Time: 14:13:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.2730
Nobs: 420.000 HQIC: -46.7965
Log likelihood: 4625.54 FPE: 3.37246e-21
AIC: -47.1387 Det(Omega_mle): 2.72882e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.440578 0.092510 4.763 0.000
L1.Burgenland 0.102171 0.047773 2.139 0.032
L1.Kärnten -0.114825 0.023863 -4.812 0.000
L1.Niederösterreich 0.161143 0.102231 1.576 0.115
L1.Oberösterreich 0.115246 0.100430 1.148 0.251
L1.Salzburg 0.285415 0.050137 5.693 0.000
L1.Steiermark 0.028537 0.066553 0.429 0.668
L1.Tirol 0.108681 0.052558 2.068 0.039
L1.Vorarlberg -0.108520 0.047264 -2.296 0.022
L1.Wien -0.011141 0.091573 -0.122 0.903
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.011640 0.213095 0.055 0.956
L1.Burgenland -0.048568 0.110044 -0.441 0.659
L1.Kärnten 0.036832 0.054967 0.670 0.503
L1.Niederösterreich -0.214625 0.235488 -0.911 0.362
L1.Oberösterreich 0.481882 0.231341 2.083 0.037
L1.Salzburg 0.307700 0.115490 2.664 0.008
L1.Steiermark 0.117638 0.153304 0.767 0.443
L1.Tirol 0.314510 0.121066 2.598 0.009
L1.Vorarlberg 0.002670 0.108873 0.025 0.980
L1.Wien 0.001950 0.210938 0.009 0.993
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.246074 0.047031 5.232 0.000
L1.Burgenland 0.090145 0.024287 3.712 0.000
L1.Kärnten -0.002065 0.012131 -0.170 0.865
L1.Niederösterreich 0.211602 0.051973 4.071 0.000
L1.Oberösterreich 0.166656 0.051058 3.264 0.001
L1.Salzburg 0.034881 0.025489 1.368 0.171
L1.Steiermark 0.018399 0.033835 0.544 0.587
L1.Tirol 0.069044 0.026720 2.584 0.010
L1.Vorarlberg 0.057080 0.024029 2.376 0.018
L1.Wien 0.109802 0.046555 2.359 0.018
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182449 0.045986 3.968 0.000
L1.Burgenland 0.048380 0.023748 2.037 0.042
L1.Kärnten -0.006728 0.011862 -0.567 0.571
L1.Niederösterreich 0.138920 0.050818 2.734 0.006
L1.Oberösterreich 0.316282 0.049923 6.335 0.000
L1.Salzburg 0.101300 0.024923 4.065 0.000
L1.Steiermark 0.131742 0.033083 3.982 0.000
L1.Tirol 0.076797 0.026126 2.939 0.003
L1.Vorarlberg 0.056311 0.023495 2.397 0.017
L1.Wien -0.045701 0.045520 -1.004 0.315
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206463 0.091357 2.260 0.024
L1.Burgenland -0.048604 0.047178 -1.030 0.303
L1.Kärnten -0.034741 0.023565 -1.474 0.140
L1.Niederösterreich 0.106836 0.100957 1.058 0.290
L1.Oberösterreich 0.165229 0.099179 1.666 0.096
L1.Salzburg 0.253476 0.049512 5.119 0.000
L1.Steiermark 0.080857 0.065724 1.230 0.219
L1.Tirol 0.126080 0.051903 2.429 0.015
L1.Vorarlberg 0.115768 0.046675 2.480 0.013
L1.Wien 0.032597 0.090432 0.360 0.719
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.032077 0.070650 0.454 0.650
L1.Burgenland 0.023549 0.036484 0.645 0.519
L1.Kärnten 0.052371 0.018224 2.874 0.004
L1.Niederösterreich 0.210814 0.078074 2.700 0.007
L1.Oberösterreich 0.334020 0.076699 4.355 0.000
L1.Salzburg 0.044832 0.038290 1.171 0.242
L1.Steiermark -0.004324 0.050827 -0.085 0.932
L1.Tirol 0.113040 0.040138 2.816 0.005
L1.Vorarlberg 0.065737 0.036096 1.821 0.069
L1.Wien 0.128928 0.069934 1.844 0.065
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184686 0.086509 2.135 0.033
L1.Burgenland 0.018495 0.044674 0.414 0.679
L1.Kärnten -0.057632 0.022315 -2.583 0.010
L1.Niederösterreich -0.115599 0.095599 -1.209 0.227
L1.Oberösterreich 0.183453 0.093916 1.953 0.051
L1.Salzburg 0.031327 0.046885 0.668 0.504
L1.Steiermark 0.299822 0.062236 4.818 0.000
L1.Tirol 0.487651 0.049148 9.922 0.000
L1.Vorarlberg 0.076304 0.044198 1.726 0.084
L1.Wien -0.106043 0.085633 -1.238 0.216
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161166 0.094205 1.711 0.087
L1.Burgenland -0.010537 0.048648 -0.217 0.829
L1.Kärnten 0.063353 0.024300 2.607 0.009
L1.Niederösterreich 0.195310 0.104104 1.876 0.061
L1.Oberösterreich -0.131639 0.102271 -1.287 0.198
L1.Salzburg 0.237171 0.051056 4.645 0.000
L1.Steiermark 0.154690 0.067772 2.282 0.022
L1.Tirol 0.047316 0.053521 0.884 0.377
L1.Vorarlberg 0.130893 0.048130 2.720 0.007
L1.Wien 0.154938 0.093251 1.662 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488690 0.051087 9.566 0.000
L1.Burgenland -0.008494 0.026382 -0.322 0.747
L1.Kärnten -0.010150 0.013178 -0.770 0.441
L1.Niederösterreich 0.201539 0.056456 3.570 0.000
L1.Oberösterreich 0.260408 0.055462 4.695 0.000
L1.Salzburg 0.021172 0.027688 0.765 0.444
L1.Steiermark -0.023409 0.036753 -0.637 0.524
L1.Tirol 0.067505 0.029024 2.326 0.020
L1.Vorarlberg 0.058744 0.026101 2.251 0.024
L1.Wien -0.052854 0.050570 -1.045 0.296
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021493 0.076410 0.141735 0.130889 0.042448 0.075144 -0.004516 0.178441
Kärnten 0.021493 1.000000 -0.044581 0.127260 0.046708 0.069024 0.454582 -0.093518 0.091649
Niederösterreich 0.076410 -0.044581 1.000000 0.283428 0.082248 0.264432 0.020173 0.138032 0.258378
Oberösterreich 0.141735 0.127260 0.283428 1.000000 0.179864 0.284983 0.155555 0.100544 0.139542
Salzburg 0.130889 0.046708 0.082248 0.179864 1.000000 0.125608 0.055412 0.104477 0.052155
Steiermark 0.042448 0.069024 0.264432 0.284983 0.125608 1.000000 0.129677 0.090009 -0.022259
Tirol 0.075144 0.454582 0.020173 0.155555 0.055412 0.129677 1.000000 0.045261 0.115474
Vorarlberg -0.004516 -0.093518 0.138032 0.100544 0.104477 0.090009 0.045261 1.000000 -0.048567
Wien 0.178441 0.091649 0.258378 0.139542 0.052155 -0.022259 0.115474 -0.048567 1.000000